<template>
    <div>
        <!-- 表格操作项 start  -->
        <Button v-for="(item, index) in tableBtn" :key="index" type="primary" :icon="item.icon" class="ivu-mr-8"
            @click="tableTopOperate(item.name)">{{ item.label }}</Button>
        <!-- <Button icon="md-list"
                class="ivu-ml-8"
                v-show="tableBatchBtns && tableBatchBtns.length>0 && tableSelectData &&tableSelectData.length">批量操作</Button> -->
        <Dropdown class="ivu-ml-8" v-show="tableSelectData && tableSelectData.length>0" @on-click="handleClickItem">
            <Button>更多操作
                <Icon type="ios-arrow-down" />
            </Button>
            <DropdownMenu slot="list">
              <template v-for="(item, index) in tableBatchBtns">
                <DropdownItem  :key="index" :name="item.name" v-if="showBtn(item.label)">{{item.label}}
                </DropdownItem>
              </template>

            </DropdownMenu>
        </Dropdown>
        <!-- 表格操作项 end  -->
    </div>
</template>
<script>
    import dynamictablebtns from '@/mixins/dynamictablebtns'; // 混入通用代码
    import { ApiRequest } from '@api/basePage';
    import { mapGetters } from 'vuex';
    export default {
        mixins: [
            dynamictablebtns
        ],
        data() {
            return {
            }
        },
        methods: {
            handleClickItem(name) {
                if (name === 'delete') {
                    let uuidArr = [];
                    let isCan = true
                    this.tableSelectData.forEach(item => {
                        uuidArr.push(item.uuid)
                        // if (item.editStatus !== '3') {
                        //     isCan = false;
                        // }
                    });
                    //if (isCan) {
                        this.$Modal.confirm({
                            title: '批量删除',
                            content: '确定要批量删除这些归类吗？',
                            onOk: () => {
                                let data = {
                                    uuids: uuidArr.join(',')
                                }
                                // 开始请求列表
                                ApiRequest(this.requestApi.delTableList.url, this.requestApi.delTableList.type, data, true).then(res => {
                                    if (res.retStatus === '1') {
                                        this.$Message.success('批量删除成功');
                                        this.tableSelectData = [];
                                        this.actionsChange();
                                    }
                                })
                            }
                        })
                    //}
                    // else {
                    //     this.$Message.info('您选择的数据中包含不能删除的数据!');
                    // }
                }else if (name === 'reAudit') {
                    let uuidArr = [];
                    this.tableSelectData.forEach(item => {
                        uuidArr.push(item.uuid);
                    });
                    this.$Modal.confirm({
                        title: '批量提交审核',
                        content: '确定批量审核此数据吗？',
                        onOk: () => {
                            let data = {
                                uuids: uuidArr.join(',')
                            }
                            // 开始请求商品列表
                            ApiRequest(
                                this.requestApi.reAudit.url,
                                this.requestApi.reAudit.type,
                                data, true
                            ).then(res => {
                                if (res.retStatus === '1') {
                                    this.$Message.success('提交成功')
                                    this.tableSelectData=[];
                                    this.actionsChange();
                                }
                            })
                        }
                    })
                }
            }
        },
        computed: {
        ...mapGetters('permissions/systemBtns', [
          'showBtn'
        ]),
      },
    }
</script>
